<template>
  <div style="padding: 20px 20px 20px 0px;">
    <el-row :gutter="40">
      <el-col :span="5">
        <tree @handleNode="handleNode" @handleCheck="handleCheck"></tree>
      </el-col>
      <el-col :span="19">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="100px">
          <el-form-item label="时间范围" prop="dateType">
            <el-select v-model="queryParams.dateType" placeholder="请选时间范围" clearable>
              <el-option v-for="dict in dict.type.sys_date_type" :key="dict.value" :label="dict.label"
                :value="dict.value"/>
            </el-select>
          </el-form-item>
          <!-- <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> -->
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <line_chart :chartData="chartData"></line_chart>
      </el-col>
    </el-row>


  </div>
</template>
<script>
  import {
    listCommodity
  } from "@/api/hd/commodity";
  import {
    listCommodityTime,
    getCommodityTimes,
    listCommodityTimeBydateTime,

  } from "@/api/hd/commodityTime";

  import tree from "@/components/Tree";
  import line_chart from "@/views/hd/calculation/chart/lineChart";

  export default {
    name: "Calculation",
    dicts: ['hd_commodity_status', 'hd_commodity_type', 'sys_date_type'],
    components: {
      tree,
      line_chart
    },
    data() {
      return {
        filterText: '',
        commodityTimeList: [],
        data: [],
        treeList: [],
        total: null,
        defaultProps: {
          children: 'children',
          label: 'name'
        },
        chartData: {
          commodityId: null,
          dateType: null,
        },
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 商品记录管理表格数据
        commodityTimeList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          id: null,
          name: null,
          price: null,
          batch: null,
          type: null,
          status: null,
          imagUrl: null,
          fileUrl: null,
          commodityId: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          dateType: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          id: [{
            required: true,
            message: "商品编码不能为空",
            trigger: "blur"
          }],
          name: [{
            required: true,
            message: "商品名称不能为空",
            trigger: "blur"
          }],
          price: [{
            required: true,
            message: "商品价格不能为空",
            trigger: "blur"
          }],
          batch: [{
            required: true,
            message: "商品批次号不能为空",
            trigger: "blur"
          }],
          type: [{
            required: true,
            message: "商品类型不能为空",
            trigger: "change"
          }],
          status: [{
            required: true,
            message: "商品状态不能为空",
            trigger: "blur"
          }],
          imagUrl: [{
            required: true,
            message: "图片地址不能为空",
            trigger: "blur"
          }],
          fileUrl: [{
            required: true,
            message: "文件地址不能为空",
            trigger: "blur"
          }],
          commodityId: [{
            required: true,
            message: "关联商品编码不能为空",
            trigger: "blur"
          }],
          createBy: [{
            required: true,
            message: "创建者不能为空",
            trigger: "blur"
          }],
          createTime: [{
            required: true,
            message: "创建时间不能为空",
            trigger: "blur"
          }],
          updateBy: [{
            required: true,
            message: "更新者不能为空",
            trigger: "blur"
          }],
          updateTime: [{
            required: true,
            message: "更新时间不能为空",
            trigger: "blur"
          }]
        }
      };
    },
    watch: {
      filterText(val) {
        console.log(val)
        this.$refs.tree.filter(val);
      }
    },
    created() {

    },
    mounted() {
      this.getList()
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 查询商品管理列表 */
      getList() {
        this.loading = true;
        listCommodity({}).then(response => {
          this.data = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      filterNode(value, data) {
        if (!value) return true;
        console.log(value)
        return data.name.indexOf(value) !== -1;
      },
      handleNode(data) {
        this.chartData = {
          commodityId: data.data.id,
          name:data.data.name,
          dateType: this.queryParams.dateType
        };
      },
      handleCheck(data) {
        // getCommodityTimes(data.checkedKeys).then(response => {
        // this.commodityTimeList = response.data;
        // console.log(this.commodityTimeList)
        // this.total = response.total;
        // this.loading = false;
        // });
        // console.log(data);
      }
    },
  };
</script>
